package com.guocheng.quartz.everyday;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class Quartz {

    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(Job.class).withIdentity("job","everyday").storeDurably().build();
    }

    @Bean
    public Trigger trigger() {
        //每日凌晨2点执行
        return TriggerBuilder.newTrigger().forJob(jobDetail())
                .withIdentity("trigger","everyday")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 2 * * ? *"))
                .build();
    }
}
